
<template>
  <div class="risk">
    <div class="danger-menu">
      <div class="danger-menu-list" @click="goCourseware()">
        <img
          src="@/assets/Images/AppIcon/icon_training_res_center.png"
          alt=""
        />
        <div>课件中心</div>
      </div>
      <div class="danger-menu-list" @click="_goMustStudy()">
        <img src="@/assets/Images/AppIcon/icon_training_job_study.png" alt="" />
        <div>岗位必学</div>
      </div>
    </div>
    <!-- 隐患排查治理 -->
    <div class="content">
      <van-divider><span class="danger-title">学习考试</span></van-divider>
      <div class="list">
        <div class="list-title">我的学习<span>我的考试培训计划</span></div>
        <div class="content-menu">
          <div class="content-menu-list" @click="goMyTask()">
            <van-badge :content="list.TrainPlanAlloc">
              <img
                src="@/assets/Images/AppIcon/icon_training_study_plan.png"
                alt=""
              />
            </van-badge>
            <div>培训计划</div>
          </div>

          <div class="content-menu-list" @click="goMyExExam()">
            <van-badge :content="list.ExamAlloc">
              <img
                src="@/assets/Images/AppIcon/icon_training_my_examine.png"
                alt=""
              />
            </van-badge>
            <div>我的考试</div>
          </div>
        </div>
      </div>
      <div class="list">
        <div class="list-title">
          学习收藏<span>当前学习过的历史及收藏内容</span>
        </div>
        <div class="content-menu">
          <div class="content-menu-list" @click="goMyMeasures()">
            <img
              src="@/assets/Images/AppIcon/icon_training_study_history.png"
              alt=""
            />
            <div>学习历史</div>
          </div>
          <div class="content-menu-list" @click="goMyCollection()">
            <img
              src="@/assets/Images/AppIcon/icon_training_my_collect.png"
              alt=""
            />
            <div>我的收藏</div>
          </div>
        </div>
      </div>
      <div class="list">
        <div class="list-title">
          我的任务<span>需要我操作的相关学习过程的任务</span>
        </div>
        <div class="content-menu">
          <div class="content-menu-list" @click="goExamReview()">
            <van-badge :content="list.ExamMarking">
              <img
                src="@/assets/Images/AppIcon/icon_training_marking.png"
                alt=""
              />
            </van-badge>
            <div>试卷批阅</div>
          </div>
          <div class="content-menu-list" @click="goPracticeAssessment()">
            <van-badge :content="list.TrainPlanPracticeCheck"
              ><img
                src="@/assets/Images/AppIcon/icon_training_check.png"
                alt=""
            /></van-badge>
            <div>实践考核</div>
          </div>
        </div>
      </div>
    </div>
    <template v-if="roles.indexOf('admin') != -1">
      <div class="content">
        <van-divider><span class="danger-title">培训管理</span></van-divider>
        <div class="list">
          <div class="list-title">
            培训计划<span>可创建及追踪计划详情</span>
          </div>
          <div class="content-menu">
            <div class="content-menu-list" @click="goAddTrainingPlan()">
              <img
                src="@/assets/Images/AppIcon/icon_danger_main_checktask.png"
                alt=""
              />
              <div>创建培训计划</div>
            </div>
            <div class="content-menu-list" @click="goTrainingPlanList()">
              <img
                src="@/assets/Images/AppIcon/icon_training_study_plan.png"
                alt=""
              />
              <div>培训计划清单</div>
            </div>
          </div>
        </div>
        <div class="list">
          <div class="list-title">考试计划<span>最专业的考试试题</span></div>
          <div class="content-menu">
            <div class="content-menu-list" @click="goAddExam()">
              <img
                src="@/assets/Images/AppIcon/icon_danger_main_approve.png"
                alt=""
              />
              <div>创建考试</div>
            </div>
            <div class="content-menu-list" @click="goExamplan()">
              <img
                src="@/assets/Images/AppIcon/icon_training_my_examine.png"
                alt=""
              />
              <div>考试计划清单</div>
            </div>
          </div>
        </div>
      </div>
    </template>
  </div>
</template>

<script>
import { list } from "@/api/train";
import store from "@/store/index";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      list: {},
    };
  },
  beforeRouteLeave(to, from, next) {
    if (to.name == "AddTrainingPlan") {
      to.meta.title = "创建培训计划";
    }
    if (to.name == "AddExam") {
      to.meta.title = "创建考试";
    }
    next(); //继续下一步
  },
  created() {
    // if (this.$route.query.sessionId) {
    //   store.state.sessionId = this.$route.query.sessionId;
    // }

    this.getList();
  },
  computed: {
    ...mapGetters(["baseUrl", "roles"]),
  },
  // mounted() {
  // 	window.history.pushState(null, null, document.URL)
  // 	window.addEventListener('popstate', this.onBrowserBack, false)
  // },
  // destroyed() {
  // 	window.removeEventListener('popstate', this.onBrowserBack, false)
  // },

  methods: {
    // onBrowserBack() {
    // 	this.$router.replace('/index')
    // },
    getList() {
      list().then((res) => {
        let newObj = {};
        res.data.map((item, index) => {
          let newkey = item.TemplateCode;
          let newValue = item.Cnt;
          newObj[newkey] = item.Cnt;
        });

        this.list = newObj;
        // this.list = res.data
        // console.log(res, 'res')
      });
    },
    // 岗位必学
    _goMustStudy() {
      this.$router.push({
        path: "/Train/MustStudy",
        query: {},
      });
    },
    goCourseware() {
      this.$router.push({
        path: "/Train/Courseware",
        query: {},
      });
    },
    // 培训计划
    goMyTask() {
      this.$router.push({
        path: "/Train/Trainingplan",
        query: {},
      });
    },

    goExamplan() {
      this.$router.push({
        path: "/Train/Examplan",
        query: {},
      });
    },
    // 学习历史
    goMyMeasures() {
      this.$router.push({
        path: "/Train/LearningHistory",
        query: {},
      });
    },
    // 我的考试
    goMyExExam() {
      store.commit("updateResultID", null);
      this.$router.push({
        path: "/Train/ExExam",
        query: {},
      });
    },

    goAddTrainingPlan() {
      this.$router.push({
        path: "/Train/AddTrainingPlan",
        query: {
          id: 0,
        },
      });
    },

    goTrainingPlanList() {
      this.$router.push({
        path: "/Train/TrainingPlanList",
        query: {},
      });
    },
    // 试卷批阅
    goExamReview() {
      this.$router.push({
        path: "/Train/ExamReviewList",
        query: {},
      });
    },
    goMyCollection() {
      this.$router.push({
        path: "/Train/MyCollection",
        query: {},
      });
    },
    // 实践考核
    goPracticeAssessment() {
      this.$router.push({
        path: "/Train/PracticeAssessment",
        query: {},
      });
    },
    // 创建考试
    goAddExam() {
      this.$router.push({
        path: "/Train/AddExam",
        query: {
          id: 0,
        },
      });
    },
  },
};
</script>

<style lang="less" scoped>
.risk {
  background-color: #e8f1f8;
}
.danger-menu {
  display: flex;
  width: 100%;
  height: 100px;
  background-color: #383d40;
  .danger-menu-list {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #fff;
    img {
      width: 55px;
      height: 55px;
      margin-bottom: 10px;
    }
  }
}
.content {
  background-color: #fff;
  padding-top: 0;
  padding-bottom: 0;

  overflow: hidden;
  margin-bottom: 10px;
  .danger-title {
    color: orange;
    font-weight: bold;
  }
  .list {
    background-color: #f8f8f8;
    padding: 10px;
    font-size: 14px;
    border-radius: 5px;
    margin-bottom: 10px;
    .list-title {
      color: #000;
      span {
        font-size: 10px;
        margin-left: 15px;
        color: #666;
      }
    }
    .content-menu {
      display: flex;
      width: 100%;
      margin: 20px 0 10px 0;
      .content-menu-list {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 13px;

        img {
          width: 25px;
          height: 25px;
          margin-bottom: 15px;
        }
        span {
          margin-top: 10px;
          font-size: 8px;
          color: #666;
        }
      }
    }
  }
}
</style>